package com.runen.wnhz.runen.ui.adapter.puadapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.TextView;

import com.runen.wnhz.runen.R;
import com.runen.wnhz.runen.bean.CanDownloadLessonBean;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class CanDownloadLessonAdapter extends BaseAdapter {

    private Context context;

    private List<CanDownloadLessonBean.DataBean> dataBeanList;

    private int totalSmallSelection;

    public CanDownloadLessonAdapter(Context context, List<CanDownloadLessonBean.DataBean> data,int totalSmallSelection) {
        this.context = context;
        this.dataBeanList = data;
        this.totalSmallSelection = totalSmallSelection;
    }

    @Override
    public int getCount() {
        if(dataBeanList != null){
            return dataBeanList.size();
        }else{
            return 0;
        }
    }

    @Override
    public Object getItem(int i) {
        return null;
    }

    @Override
    public long getItemId(int i) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup viewGroup) {
        ViewHolder viewHolder;
        if(convertView == null){
            convertView = View.inflate(context, R.layout.can_download_liat_item_layout,null);
            viewHolder = new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        }else{
            viewHolder = (ViewHolder)convertView.getTag();
        }

        CanDownloadLessonBean.DataBean dataBean = dataBeanList.get(position);
        viewHolder.text_downloadTitle.setText(dataBean.getTitle());
        viewHolder.list_smallSelection.setAdapter(new CanDownloadSmallLessonAdapter(context,dataBean.getNext_list(),totalSmallSelection));

        return convertView;
    }

    static class ViewHolder{

        @BindView(R.id.text_downloadTitle)
        TextView text_downloadTitle;
        @BindView(R.id.list_smallSelection)
        ListView list_smallSelection;

        public ViewHolder(View convertView) {
            ButterKnife.bind(this,convertView);
        }
    }
}
